package com.hdjk.view.callback;

import com.hdjk.view.entity.CustomFundEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class CustomFundListCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONArray array = (JSONArray) msg.getData();
        if (array != null && array.length() > 0) {
            List<CustomFundEntity> list = new ArrayList<>();
            for (int j = 0; j < array.length(); j++) {
                JSONObject jsonObject = array.getJSONObject(j);
                CustomFundEntity entity = new CustomFundEntity();
                if (!jsonObject.isNull("FundName")) {
                    entity.setFundName(jsonObject.getString("FundName"));
                }
                if (!jsonObject.isNull("FundCode")) {
                    entity.setFundCode(jsonObject.getString("FundCode"));
                }
                if (!jsonObject.isNull("FundCustodian")) {
                    entity.setFundCustodian(jsonObject.getString("FundCustodian"));
                }
                if (!jsonObject.isNull("Remark")) {
                    entity.setRemark(jsonObject.getString("Remark"));
                }
                if (!jsonObject.isNull("CreateTime")) {
                    entity.setCreateTime(jsonObject.getString("CreateTime"));
                }
                if (!jsonObject.isNull("ModifyTime")) {
                    entity.setModifyTime(jsonObject.getString("ModifyTime"));
                }
                if (!jsonObject.isNull("Hidden")) {
                    entity.setHidden(jsonObject.getBoolean("Hidden"));
                }
                if (!jsonObject.isNull("State")) {
                    entity.setState(jsonObject.getString("State"));
                }
                if (!jsonObject.isNull("ExtAttrs")) {
                    entity.setExtAttrs(jsonObject.getString("ExtAttrs"));
                }
                if (!jsonObject.isNull("MinInitialIpoAmount")) {
                    entity.setMinInitialIpoAmount(jsonObject.getString("MinInitialIpoAmount"));
                }
                if (!jsonObject.isNull("EndDate")) {
                    entity.setEndDate(jsonObject.getString("EndDate"));
                }
                if (!jsonObject.isNull("LaunchDate")) {
                    entity.setLaunchDate(jsonObject.getString("LaunchDate"));
                }
                if (!jsonObject.isNull("InvestmentObjective")) {
                    entity.setInvestmentObjective(jsonObject.getString("InvestmentObjective"));
                }
                if (!jsonObject.isNull("FundType")) {
                    entity.setFundType(jsonObject.getString("FundType"));
                }
                if (!jsonObject.isNull("LaunchSize")) {
                    entity.setLaunchSize(jsonObject.getString("LaunchSize"));
                }
                if (!jsonObject.isNull("MinSubseqIpoAmount")) {
                    entity.setMinSubseqIpoAmount(jsonObject.getString("MinSubseqIpoAmount"));
                }
                if (!jsonObject.isNull("IpoStartDate")) {
                    entity.setIpoStartDate(jsonObject.getString("IpoStartDate"));
                }
                if (!jsonObject.isNull("UpdateTime")) {
                    entity.setUpdateTime(jsonObject.getString("UpdateTime"));
                }
                if (!jsonObject.isNull("Id")) {
                    entity.setId(jsonObject.getString("Id"));
                }
                list.add(entity);
            }
            msg.setData(list);
        } else {
            msg.setData("");
        }
        return msg;
    }
}
